<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title> 店铺发货</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/Public/admin/adminlte/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/font-awesome/font-awesome.min.css">
    <!-- Ionicons -->
    <!--link rel="stylesheet" href="/Public/admin/adminlte/plugins/ionicons/ionicons.min.css"-->
    <!-- Theme style -->
    <link rel="stylesheet" href="/Public/admin/adminlte/dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="/Public/admin/adminlte/dist/css/skins/_all-skins.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/iCheck/flat/blue.css">
    <!-- Morris chart -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/morris/morris.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/daterangepicker/daterangepicker.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <!-- common css -->
    <link rel="stylesheet" href="/Public/admin/css/common.css">
    <!-- jQuery 2.2.3 -->
    <script src="/Public/admin/adminlte/plugins/jQuery/jquery-2.2.3.min.js"></script>
    <!-- jQuery UI 1.11.4 -->
    <script src="/Public/admin/adminlte/bootstrap/js/jquery-ui.min.js"></script>
    <script src="/Public/admin/js/jquery.validate.min.js"></script>
    <script src="/Public/admin/js/jquery.validate.config.js"></script>
    <script src="/Public/admin/js/common.js?v=20170331001"></script>
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="/Public/admin/adminlte/plugins/html5shiv/html5shiv.min.js"></script>
    <script src="/Public/admin/adminlte/plugins/html5shiv/respond.min.js"></script>
    <![endif]-->
</head>
<body class="hold-transition skin-blue sidebar-mini">



    <!-- 内容 -->
    <section class="content" >


        <div class="box box-default">
            <div class="box-header with-border">
                <h3 class="box-title">发货:<?php echo ($delivery['detail']['order_id']); ?>
                   </h3>
            </div>
            <!-- /.box-header -->

      <form method="post" action="<?php echo U('orders/doDelivery');?>"   id="order-delivery-form">
            <div class="box-body">


                <table cellpadding="0" cellspacing="0" class="table table-bordered" id="tb1">
                    <tbody><tr>
                        <th>订单号:</th>
                        <td><?php echo ($delivery["detail"]["order_id"]); ?>
                            【 <?php if($delivery['detail']['ship_status'] == 0 ): ?>未发货
                                <?php elseif($delivery['detail']['ship_status'] == 1): ?>已发货
                                <!--<?php elseif($delivery['detail']['ship_status'] == 2): ?>部分发货
                                <?php elseif($delivery['detail']['ship_status'] == 3): ?>部分退货
                                <?php elseif($delivery['detail']['ship_status'] == 4): ?>已退货--><?php endif; ?> 】

                        </td>
                        <th>下单日期:</th>
                        <td><?php echo ($delivery["detail"]["createtime"]); ?></td>
                    </tr>
                    <tr>
                        <th>配送方式:</th>
                        <td>
                            <select type="select" name="delivery" id="delivery" class=" x-select">
                               <?php if(is_array($delivery['dlytype'])): $i = 0; $__LIST__ = $delivery['dlytype'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$item): $mod = ($i % 2 );++$i;?><option value="<?php echo ($item["dt_id"]); ?>" <?php if($item['dt_id'] == $delivery['Select_dt']['dt_id']): ?>selected="selected"<?php endif; ?>>
                                   <?php echo ($item["dt_name"]); ?>
                                   </option><?php endforeach; endif; else: echo "" ;endif; ?>
                            </select></td>
                        <th>配送费用:</th>
                        <td>￥<?php echo (number_format($delivery["detail"]["cost_freight"], 2, '.', '')); ?> </td>
                    </tr>
                    <tr class="shop-delivery <?php if($delivery['Select_dt']['dt_id'] != 1): ?>hide<?php endif; ?>" >
                        <th>配送人姓名:</th>
                        <td><div><div><input type="text" name="delivName" value=""></div></div></td>
                        <th>配送人电话:</th>
                        <td><div><div><input type="text" name="delivMobile" value=""></div></div> </td>
                    </tr>



                    <tr <?php if($delivery['Select_dt']['dt_id'] == 3): ?>class='hide'<?php endif; ?> id='isKd'>
                        <th>物流公司:</th>
                        <td>
                            <select   type="select" name="logi_id" id="logi_id" class=" x-select">
                                <option value="0">选择物流公司</option>
                                <?php if(is_array($delivery['dlycorp'])): $i = 0; $__LIST__ = $delivery['dlycorp'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$item): $mod = ($i % 2 );++$i;?><option value="<?php echo ($item['corp_id']); ?>"  <?php if($delivery['se_corp_id'] == $item['corp_id']): ?>selected="selected"<?php endif; ?>><?php echo ($item['name']); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
                            </select>

                        </td>
                        <th>物流单号:</th>
                        <td><div><div><input class="x-input" type="text" id="logi_no" name="logi_no" width="100" ></div></div></td>
                    </tr>
                    <?php if($delivery['detail']['is_zt'] != 1): ?><input type="hidden" name="is_aa" value="no_zt" />
                     <?php else: ?>
                        <input type="hidden" name="is_aa" value="zt" /><?php endif; ?>
                    <tr>
                        <?php if($delivery['detail']['is_zt'] != 1): ?><th>物流费用:</th>
                         <td><input class="x-input" type="text" id="money"  name="money" value="<?php echo (number_format($delivery["detail"]["cost_freight"], 2, '.', '')); ?>" width="50"></td>
                            <th>邮政编码:</th>
                            <td><div><div><input class="x-input" type="text" name="ship_zip" id="ship_zip" value="<?php echo ($delivery["detail"]["ship_zip"]); ?>" width="80"></div></div></td>
                        <?php else: ?>
                            <input class="x-input" type="hidden" id="money"  name="money" value="<?php echo (number_format($delivery["detail"]["cost_freight"], 2, '.', '')); ?>" width="50"><?php endif; ?>





                        <!--<th>物流保价:</th>
                        <td>
                            <input name="is_protect" type="radio" id="dom_el_e543c83-1" value="false" checked="checked"><label for="dom_el_e543c83-1">否</label><br><input name="is_protect" type="radio" id="dom_el_e543c83-2" value="true"><label for="dom_el_e543c83-2">是</label></td>
                    </tr>
                    <tr>
                        <th>保价费用:</th>
                        <td colspan="3"><input class="x-input" type="text" name="cost_freight" value="0.000" width="50" id="dom_el_e543c84"></td>
                    </tr>-->
                    <tr>
                        <th>收货人姓名:</th>
                        <td><div><div><input class="x-input" type="text" name="ship_name" id="ship_name" value="<?php echo ($delivery["detail"]["ship_name"]); ?>" width="80"></div></div></td>
                        <th>手机:</th>
                        <td><div><div><input class="x-input" type="text" name="ship_mobile" id="ship_mobile" value="<?php echo ($delivery["detail"]["ship_mobile"]); ?>" width="150">
                        </div></div></td>

                    </tr>

                    <tr>
                        <th>地区:</th>
                        <td colspan="3">
                            <?php echo ($delivery["detail"]["ship_area"]); ?>
                            <input type="hidden" value="<?php echo ($delivery["detail"]["ship_area"]); ?>" id="ship_area" name="ship_area"/>
                        </td>
                    </tr>
                    <tr>
                        <th>地址:
                        <td colspan="3"><input class="x-input" type="text" name="ship_addr" id="ship_addr" value="<?php echo ($delivery["detail"]["ship_addr"]); ?>" style="width:360px" ></td>
                    </tr>
                    <tr>
                        <th>发货单备注:</th>
  <td colspan="3"><textarea type="textarea" name="memo" id="memo" style="width:95%" ><?php echo ($delivery["detail"]["memo"]); ?></textarea></td>
                    </tr>
                    </tbody></table>


                <!-- /.row -->
            </div>
            <input type="hidden" value="<?php echo ($delivery["detail"]["order_id"]); ?>" id="order_id" name="order_id"/>
            <!-- /.box-body -->
            <div class="box-footer">
                <div class="division">
                    <table class="table table-hover" style="margin-left: 10px; width: 99%;">
                        <tbody>
                        <tr>
                            <th>货号</th>
                            <th>货品名称</th>
                            <th>当前库存</th>
                            <th>冻结</th>
                            <th>购买数量</th>
                            <th>已发货量</th>
                            <th>此单发货</th>
                        </tr>

                        <?php if(is_array($delivery["product"])): $i = 0; $__LIST__ = $delivery["product"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$item): $mod = ($i % 2 );++$i;?><tr>
                                <td><?php echo ($item["bn"]); ?></td>
                                <td><?php echo ($item["name"]); ?>
                                    <?php if($item["backsend"] != ''): ?><span style="color: #ff0000"><?php echo ($item["backsend"]); ?></span><?php endif; ?>
                                </td>
                                <td><?php echo ($item["store"]); ?></td>
                                <td><?php echo ($item["freez"]); ?></td>
                                <td><?php echo ($item["nums"]); ?></td>
                                <td><?php echo ($item["sendnum"]); ?></td>
                                <td>


                                        <?php if($item["needsend"] != 0): ?><input class="x-input" type="text" id="send" name="send[<?php echo ($item["item_id"]); ?>]" value="<?php echo ($item["needsend"]); ?>" width="50"  readonly="readonly" style="border: none"  >
                                            <?php else: ?>
                                            无需发货<?php endif; ?>



                                </td>
                            </tr><?php endforeach; endif; else: echo "" ;endif; ?>

                        <tr>

                            <td colspan="7"><div style="width: 100px; margin:0 auto; margin-top: 20px; ">
                                <button type="submit" class="btn btn-block btn-primary btn-lg"  >发货</button></div></td>

                        </tr>

                        </tbody></table>
                </div>
            </div>

      </form>

       </div>




    </section>

<!-- 底部 -->
<!-- jQuery 2.2.3 -->
<!-- Bootstrap 3.3.6 -->
<script src="/Public/admin/adminlte/bootstrap/js/bootstrap.min.js"></script>
<!-- AdminLTE App -->
<script src="/Public/admin/adminlte/dist/js/app.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="/Public/admin/adminlte/dist/js/demo.js"></script>
<script src="/Public/admin/adminlte/plugins/iCheck/icheck.min.js"></script>


<!--<script src="/Public/js/distpicker.data.js"></script>
<script src="/Public/js/distpicker.js"></script>-->
</body>
</html>



<script type="text/javascript">
    $(function() {

            window._isSaved = false;

       /* $(".distpicker1").distpicker();*/
        $("#province").val('选择省');
        $("#city").val('选择市');
        $("#area").val('选择区');

        $("#order-delivery-form").validate({
            rules: {
                money:{
                    isPrice: true
                },
                ship_mobile:{
                    isMobile: true
                },
                /*delivName:{
                    required: true,
                    maxlength: 40,
                },*/
                /*delivMobile:{
                    required: true,
                    isMobile: true,
                },*/
                logi_no:{
                    maxlength: 40,
                    number:true
                },
                ship_name: {
                    required: true,
                    maxlength: 40,
                },
                ship_zip:{
                        isZipCode: true
                }
            },
            messages:{
                ship_name:{
                    required: "请输入收货人姓名",
                    maxlength: "收货人姓名不能超过40个字符"
                },
              /*  delivMobile:{
                    required: "请输入配送人电话",
                },
                delivName:{
                    required: "请输入配送人姓名",
                    maxlength: "配送人姓名不能超过40个字符"
                },*/

            },
            submitHandler: function(form){
                //form.submit();   //提交表单
               console.log(window._isSaved);
               if(window._isSaved){
                    return;
                }

                toDelivery();

            }
        });


    })

    function toDelivery() {
       var index = parent.layer.getFrameIndex(window.name); //获取窗口索引

        $.ajax({
            url:$('form').attr('action'),
            type:'post',
            data:$('#order-delivery-form').serialize(),
            dataType:'json',
            success:function (data) {
                if(data.status ==0){
                    alert(data.msg);
                    return false;
                }else{
                   alert(data.msg);
                    window._isSaved = true;
                    $('.btn-lg').attr({"disabled":"disabled"});
                     parent.layer.close(index);
                     parent.location.reload();
                }


            },
            error:function (err) {
                alert('参数错误');
                window._isSaved = false;
            }

        })

    }
    $('#delivery').on('change',function () {
        $_this =$(this);
        if($_this.val() == 1){
            $('.shop-delivery').removeClass('hide');
        }
        if($_this.val() != 1 ){
            //快递
            $('.shop-delivery').removeClass('hide');

        }

        if($_this.val() == 2 ){
            //快递
            $('.shop-delivery').addClass('hide');

        }

        if($_this.val() != 3 ){

            $('#isKd').removeClass('hide');
        }
        if($_this.val() == 3 ){
            //快递
            $('.shop-delivery').addClass('hide');
            $('#isKd').addClass('hide');
        }


    })



</script>